package com.gakj.truck.third.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gakj.truck.third.api.service.HuaTongService;
import com.gakj.truck.third.core.domain.TruckOuman;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.ws.soap.Addressing;

/**
 * Created by gc on 2016/8/1.
 */
@Controller
@RequestMapping(value = "/")
public class HuatongController {

    private static final Logger LOGGER = LoggerFactory.getLogger(HuatongController.class);

    @Addressing
    HuaTongService huaTongService;

    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveTruck(
            @RequestParam(value = "id") Long id,
            @RequestParam(value = "imgList") String imgList,
            @RequestParam(value = "modelName") String modelName,
            @RequestParam(value = "seriesName") String seriesName,
            @RequestParam(value = "brandName") String brandName,
            @RequestParam(value = "price") Float price,
            @RequestParam(value = "showmileage") String showmileage,
            @RequestParam(value = "emission") String emission,
            @RequestParam(value = "power") String power,
            @RequestParam(value = "driveform") String driveform,
            @RequestParam(value = "firsthand", defaultValue = "1") String firsthand,
            @RequestParam(value = "color") String color,
            @RequestParam(value = "drivercard") String drivercard,
            @RequestParam(value = "contactname") String contactname,
            @RequestParam(value = "contacttel") String contacttel,
            @RequestParam(value = "seecarplace") String seecarplace,
            @RequestParam(value = "ownerdepict", defaultValue = "") String ownerdepict,
            @RequestParam(value = "createtime") String createtime,
            @RequestParam(value = "licence", defaultValue = "") String licence,
            @RequestParam(value = "vin", defaultValue = "") String vin,
            @RequestParam(value = "cardtime") String cardtime,
            @RequestParam(value = "checktime", defaultValue = "") String checktime,
            @RequestParam(value = "source", defaultValue = "0") String source,
            @RequestParam(value = "title",defaultValue = "") String title,
            @RequestParam(value = "provinceName",defaultValue = "") String provinceName,
            @RequestParam(value = "cityName",defaultValue = "") String cityName,
            @RequestParam(value = "districtName",defaultValue = "") String districtName
    ) {

        TruckOuman ouman = new TruckOuman();
        ouman.setImgList(imgList);
        ouman.setModelName(modelName);
        ouman.setSeriesName(seriesName);
        ouman.setBrandName(brandName);
        ouman.setPrice(price);
        ouman.setShowmileage(showmileage);
        ouman.setEmission(emission);
        ouman.setPower(power);
        ouman.setDriveform(driveform);
        ouman.setFirsthand(firsthand);
        ouman.setColor(color);
        ouman.setContacttel(contacttel);
        ouman.setContactname(contactname);
        ouman.setSeecarplace(seecarplace);
        ouman.setDrivercard(drivercard);
        ouman.setOwnerdepict(ownerdepict);
        ouman.setCreatetime(createtime);
        ouman.setLicence(licence);
        ouman.setVin(vin);
        ouman.setCardtime(cardtime);
        ouman.setChecktime(checktime);
        ouman.setSource(source);
        ouman.setTruckId(id);
        ouman.setTitle(title);
        ouman.setProvinceName(provinceName);
        ouman.setCityName(cityName);
        ouman.setAreaname(districtName);
        LOGGER.info("传输过来的请求参数:"+ JSON.toJSONString(ouman));
        JSONObject result  = huaTongService.saveOrUpdate(ouman);
        return result;
    }

}
